<template>
	<view class='allpage'>
		<scroll-view class="list-scroll-content" scroll-y @scrolltolower="loadData">
			<empty v-if="loaded === true && list.length === 0"></empty>
			<block v-for="(item,index) in list" :key="index">
				<view class="notice-item" @click="jumpToDetail(item.id)">
					<text class="time">{{item.create_time}}</text>
					<view class="content">
						<text class="title">{{item.title}}</text>
						<view class="img-wrapper" v-if="item.cover">
							<image class="pic" :src='item.cover'></image>
							<!-- <view class="cover">
								活动结束
							</view> -->
						</view>
						<text class="introduce" v-if="item.description">{{item.description}}</text>
						<view class="bot b-t">
							<text>查看详情</text>
							<text class="more-icon yticon icon-you"></text>
						</view>
					</view>
				</view>
			</block>
			<uni-load-more :status="loadingType"></uni-load-more>
		</scroll-view>
	</view>
</template>

<script>
	import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue';
	import empty from "@/components/empty";
	import Json from '@/Json';
	import {mapState} from 'vuex';
	export default {
		components: {
			uniLoadMore,
			empty
		},
		data() {
			return {
				list:[],
				loadingType:'more',
				loaded:false,
				page:1,
				total:0
			}
		},
		computed: {
			...mapState(['hasLogin','userInfo'])
		},
		onLoad() {
			if(!this.hasLogin){
				uni.navigateTo({
					url:'/pages/public/login'
				})
				return 
			}
			this.loadData()
			this.changes()
		},
		onPullDownRefresh() {
			this.page = 1
			this.list = []
			setTimeout(()=>{
				this.loadData()
				uni.stopPullDownRefresh()
			},1000)
			
		},
		methods: {
			loadData(){
				if(this.loadingType === 'loading'){
					//防止重复加载
					return;
				}
				this.loadingType = 'loading';
				let that = this;
				let param = {
					page:that.page,
					token:that.userInfo.token
				}
				setTimeout(()=>{
					that.$api.getUrl(that.$api._api.ApiConfigArticle,param,function(res){
						res.data.map(re=>{
							re.create_time = that.$api.timestampToTime(re.create_time*1000)
						})
						that.list = that.list.concat(res.data)
						that.loaded = true
						that.total = res.total
						if(res.total > that.list.length){
							that.loadingType = 'more'
						}else{
							that.loadingType = 'noMore'
						}
					})
					
				}, 100);	
			},
			
			jumpToDetail:function(id){
				uni.navigateTo({
					url:"/pagesA/notice/article/article?id="+id
				})
			}
		}
	}
</script>

<style lang='scss'>
	page {
		background-color: #f7f7f7;
		padding-bottom: 30rpx;
		height: 100%;
	}
	
	.allpage{
		height: calc(100% - 40px);
	}
	
	.list-scroll-content{
		height: 100%;
	}

	.notice-item {
		display: flex;
		flex-direction: column;
		align-items: center;
	}

	.time {
		display: flex;
		align-items: center;
		justify-content: center;
		height: 80rpx;
		padding-top: 10rpx;
		font-size: 26rpx;
		color: #c3c3c3;
	}

	.content {
		width: 710rpx;
		padding: 0 24rpx;
		background-color: #fff;
		border-radius: 4rpx;
	}

	.title {
		display: flex;
		align-items: center;
		height: 90rpx;
		font-size: 32rpx;
		color: #303133;
	}

	.img-wrapper {
		width: 100%;
		height: 260rpx;
		position: relative;
	}

	.pic {
		display: block;
		width: 100%;
		height: 100%;
		border-radius: 6rpx;
	}

	.cover {
		display: flex;
		justify-content: center;
		align-items: center;
		position: absolute;
		left: 0;
		top: 0;
		width: 100%;
		height: 100%;
		background-color: rgba(0, 0, 0, .5);
		font-size: 36rpx;
		color: #fff;
	}

	.introduce {
		display: inline-block;
		padding: 16rpx 0;
		font-size: 28rpx;
		color: #606266;
		line-height: 50rpx;
	}

	.bot {
		display: flex;
		align-items: center;
		justify-content: space-between;
		height: 80rpx;
		font-size: 24rpx;
		color: #707070;
		position: relative;
	}

	.more-icon {
		font-size: 32rpx;
	}
</style>
